/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mundialfp.view.tables.bombos;

import java.awt.Container;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import mundialfp.view.tables.TableBombo;
import mundialfp.view.tables.TableCustom2;
import mundialfp.view.tables.TableUtils;
import uy.com.pzit.core.util.ImageUtil;
import uy.com.pzit.fpmundialmodel.web.ws.Bombo;
import uy.com.pzit.fpmundialmodel.web.ws.Pais;

/**
 *
 * @author pferraz
 */
public class TableBomboManager {

    public void createBombosTables(int hPref, int vPref, TableCustom2 table, Container panel) {

        JScrollPane jScroll = new JScrollPane();
        jScroll.setViewportView(table);
        GroupLayout pnlLayout = new GroupLayout(panel);
        panel.setLayout(pnlLayout);
        createLayoutAndFonts(hPref, vPref, pnlLayout, jScroll, table);

    }

    private void createLayoutAndFonts(int hPref, int vPref, GroupLayout pnlLayout, JScrollPane jScroll, TableCustom2 table) {
        pnlLayout.setHorizontalGroup(
                pnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlLayout.createSequentialGroup()
                        .addComponent(jScroll, javax.swing.GroupLayout.DEFAULT_SIZE, hPref, Short.MAX_VALUE)
                        .addContainerGap())
        );
        pnlLayout.setVerticalGroup(
                pnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(vPref, Short.MAX_VALUE))
        );

        table.setFont(new java.awt.Font("Trebuchet MS", 1, 14));
    }

    public void initTableBombo(TableBombo table, Bombo bombo) {
 
        initTableBombo(table, bombo.getPaises());
        
    }

    public void initTableBombo(TableBombo table, List<Pais> paises) {
        BomboTableModel dTM = new BomboTableModel(0);
        int BANDERA_HEIGHT = 30;
        int BANDERA_WIDTH = 50;
        table.setModel(dTM);
        
        for (Pais p : paises) {
            Object[] newRow = {dTM.getRowCount() + 1, new ImageIcon(ImageUtil.resizeImage(ImageUtil.decodeToImage(p.getBanderaB64()), BANDERA_WIDTH, BANDERA_HEIGHT)), p.getNombre()};
            dTM.addRow(newRow);
        }
        TableUtils.setHeight(table, BANDERA_HEIGHT + 5);
        table.resizeColumns();
    }
}
